package org.lztvn.elearning.entities;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.hibernate.annotations.OrderBy;

@Entity
@Table(name = "topic")
public class Topic implements Serializable {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long idTopic;
	@Size(min = 4)
	@NotNull
	private String subject;
	
	@Size(min = 4)
	@NotNull
	private String description;
	
	@OneToMany(mappedBy="topic",cascade=CascadeType.REMOVE)
	private Collection<Response> listResp;
	
	@ManyToOne
	@JoinColumn(name="idUser")
	private User userOfTopic;
	
	private Date dateMsg;
	
	public Long getIdTopic() {
		return idTopic;
	}
	public void setIdTopic(Long idTopic) {
		this.idTopic = idTopic;
	}
	public String getSubject() {
		return subject;
	}
	public void setSubject(String subject) {
		this.subject = subject;
	}
	public Collection<Response> getListResp() {
		return listResp;
	}
	public void setListResp(Collection<Response> listResp) {
		this.listResp = listResp;
	}
	
	
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public User getUserOfTopic() {
		return userOfTopic;
	}
	public void setUserOfTopic(User userOfTopic) {
		this.userOfTopic = userOfTopic;
	}
	
	@OrderBy(clause = "dateMsg DESC")
	public Date getDateMsg() {
		return dateMsg;
	}
	public void setDateMsg(Date dateMsg) {
		this.dateMsg = dateMsg;
	}
	public Topic() {
		super();
		// TODO Auto-generated constructor stub
	}
	public Topic(String subject, Date DateMsg, String description) {
		super();
		this.subject = subject;
		this.dateMsg = DateMsg;
		this.description = description;
	}
	
	
}
